﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Maniac
{
    class DayAggregateSorter
    {
        /*public enum SecuritySort
        {
            AlphaAZ,
            AlphaZA,
            RiseUp,
            RiseDown,
            IndexUp,
            IndexDown,
            ActualUp,
            ActualDown,
        }*/
        private DayAggregateSorter()
        {
        }

        public static Comparison<DayAggregate> GetSort(SecuritySort SecuritySort)
        {
            switch (SecuritySort)
            {
                case SecuritySort.AlphaAZ:
                    {
                        return SortAggregatesBySymbol;                        
                    }
                case SecuritySort.AlphaZA:
                    {
                        return SortAggregatesBySymbolRev;
                    }
                case SecuritySort.RiseDown:
                    {
                        return SortAggregatesByProbability;
                    }
                case SecuritySort.AverageGainPCDown:
                    {
                        return SortAggregatesByGainPercent;
                    }
				case SecuritySort.AverageGainPCDownPriorClose:
                    {
                        return SortAggregatesByGainPercentPriorClose;
                    }
                case SecuritySort.MedianGainPCDown:
                    {
                        return SortAggregatesByMedianPercent;
                    }
				case SecuritySort.DeltaGainUp:
				{
					return SortAggregatesByStdDeviationGainPercentDelta;
	            }
			}
            return SortAggregatesBySymbol;
        }
        public static int InitializeSort(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            if (x == null)
            {
                if (y == null)
                {
                    tviReturn= 0;
                }
                else
                {
                    tviReturn= -1;
                }
            }
            else
            {
                if (y == null)
                {
                    tviReturn= 1;
                }
            }
            return tviReturn;
        }
        public static int SortAggregatesBySymbol(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x,y);
            if ((tviReturn==0)&&(x!=null)&&(y!=null))
            {              
                tviReturn = x.Symbol.CompareTo(y.Symbol);
            }
            return tviReturn;
        }
        public static int SortAggregatesBySymbolRev(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x, y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {
                tviReturn = y.Symbol.CompareTo(x.Symbol);
            }
            return tviReturn;
        }
        public static int SortAggregatesByProbability(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x,y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {
                if (x.RiseProbability > y.RiseProbability)
                    tviReturn= - 1;
                if (x.RiseProbability == y.RiseProbability)
                    tviReturn= 0;
                if (x.RiseProbability < y.RiseProbability)
                    tviReturn= 1;
            }
            return tviReturn;
        }
        public static int SortAggregatesByGain(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x,y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {
                if (x.AverageGain > y.AverageGain)
                    tviReturn= -1;
                if (x.AverageGain == y.AverageGain)
                    tviReturn= 0;
                if (x.AverageGain < y.AverageGain)
                    tviReturn= 1;
            }
            return tviReturn;
        }
        public static int SortAggregatesByGainPercent(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x,y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {

                if (x.AverageGainPercent > y.AverageGainPercent)
                    tviReturn = -1;
                if (x.AverageGainPercent == y.AverageGainPercent)
                    tviReturn = 0;
                if (x.AverageGainPercent < y.AverageGainPercent)
                    tviReturn = 1;
            }
            return tviReturn;
        }
		public static int SortAggregatesByGainPercentPriorClose(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x,y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {

                if (x.AverageGainPercentPriorClose > y.AverageGainPercentPriorClose)
                    tviReturn = -1;
                if (x.AverageGainPercentPriorClose == y.AverageGainPercentPriorClose)
                    tviReturn = 0;
                if (x.AverageGainPercentPriorClose < y.AverageGainPercentPriorClose)
                    tviReturn = 1;
            }
            return tviReturn;
        }
        public static int SortAggregatesByMedianPercent(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x, y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {

                if (x.GainPercentMedian > y.GainPercentMedian)
                    tviReturn = -1;
                if (x.GainPercentMedian == y.GainPercentMedian)
                    tviReturn = 0;
                if (x.GainPercentMedian < y.GainPercentMedian)
                    tviReturn = 1;
            }
            return tviReturn;
        }
		public static int SortAggregatesByStdDeviationGainPercentDelta(DayAggregate x, DayAggregate y)
        {
            int tviReturn = 0;
            tviReturn = InitializeSort(x,y);
            if ((tviReturn == 0) && (x != null) && (y != null))
            {
                if (x.GainPercentStandardDeviationDelta > y.GainPercentStandardDeviationDelta)
                    tviReturn = -1;
                if (x.GainPercentStandardDeviationDelta==y.GainPercentStandardDeviationDelta)
                    tviReturn = 0;
                if (x.GainPercentStandardDeviationDelta<y.GainPercentStandardDeviationDelta)
                    tviReturn = 1;
            }
            return tviReturn;
        }


    }
}
